/****************************************************
          File Name:10-4_imply.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Tue 23 Dec 2014 03:06:57 PM CST
*****************************************************/

#include"10-4.h"

namespace SALES
{
    Sales::Sales(double ar[], int n)
    {
        double ave = 0;
        double m_max = ar[0];
        double m_min = ar[0];

        for(int i = 0; i< n && i < FOUR; i++)
        {
            sales[i] = ar[i];
            ave += ar[i];

            if(m_max < ar[i]) m_max = ar[i];
            if(m_min > ar[i]) m_min = ar[i];
        }

        max = m_max;
        min = m_min;
        average = ave;
    }

    void Sales::setSale(Sales & s)
    {
        for(int i = 0; i < FOUR;  i++)
        {
            std::cout << "Enter sales: ";
            std::cin >> s.sales[i];
        }

        double ave = 0;
        double m_max = s.sales[0];
        double m_min = s.sales[0];

        for(int i = 0; i < FOUR; i++)
        {
            ave += s.sales[i];
            if(m_max < s.sales[i]) m_max = s.sales[i];
            if(m_min > s.sales[i]) m_min = s.sales[i];
        }

        s.max = m_max;
        s.min = m_min;
        s.average = ave;
    }

    void Sales::showSale(const Sales & s) const
    {
        std::cout << "Sales: ";
        for(int i = 0; i < FOUR; i++)
            std::cout << s.sales[i] << " ";
        std::cout << std::endl;
        std::cout << "Average: " << s.average << std::endl;
        std::cout << "Max: " << s.max << std::endl;
        std::cout << "Min: " << s.min << std::endl;
    }
}
